package L7_0317;

public class Main {
    public static void printOlderThan(Person[] persons, int age) {
        for (Person person : persons) {
            if (person.getAge() > age) {
                person.print();
            }
        }
    }

    public static void printPerson(Person[] persons, Check check) {
        for (Person person : persons) {
            if (check.test(person)) {
                person.print();
            }
        }
    }

    public static void main(String[] args) {
        // 创建一个包含10个Person对象的数组
        Person[] persons = new Person[10];

        // 初始化数组中的每个Person对象
        persons[0] = new Person("zhangsan", 18, "male", 10000);
        persons[1] = new Person("lisi", 20, "female", 20000);
        persons[2] = new Person("wangwu", 22, "male", 30000);
        persons[3] = new Person("zhaoliu", 24, "female", 40000);
        persons[4] = new Person("qianqi", 26, "male", 50000);
        persons[5] = new Person("sunba", 28, "female", 60000);
        persons[6] = new Person("zhouqi", 30, "male", 70000);
        persons[7] = new Person("wujiu", 32, "female", 80000);
        persons[8] = new Person("zhengliu", 34, "male", 90000);
        persons[9] = new Person("weisi", 36, "female", 100000);

//        // 调用printOlderThan方法，打印年龄大于30岁的Person对象信息
//        printOlderThan(persons, 30);
//        // 打印分隔线
//        System.out.println("---------------------");
//        // 调用printPerson方法，打印工资大于50000的Person对象信息
//        printPerson(persons, new AgeCheck28_30());
//        // 打印分隔线
//        System.out.println("---------------------");
//        // 调用printPerson方法，打印年龄大于28岁的Person对象信息
//        printPerson(persons, new MaleCheck());
        // 打印分隔线
        System.out.println("---------------------");
        printPerson(persons, new SalaryCheck());
        // 打印分隔线
        System.out.println("---------------------");
        printPerson(persons, new AgeCheck28_30());
        // 打印分隔线
        System.out.println("---------------------");
        printPerson(persons, new MaleCheck());
        // 打印分隔线
        System.out.println("---------------------");
        printPerson(persons, new FemaleCheck());
        // 打印分隔线
        System.out.println("---------------------");
        printPerson(persons, new Check() {
            @Override
            public boolean test(Person person) {
                return person.getSalary() > 50000;
            }
        });
        // 打印分隔线
        System.out.println("---------------------");
        printPerson(persons,p -> p.getSalary() > 50000 && p.getAge() > 30);


        // 使用for循环遍历数组并打印每个Person对象的信息
//        for (int i = 0; i < persons.length; i++) {
//            persons[i].print();
//        }
        // 打印分隔线
//        System.out.println("---------------------");
        // 使用增强for循环遍历数组并打印每个Person对象的信息
//        for (Person person : persons) {
//            person.print();
//        }



//        Person person = new Person("zhangsan", 18, "male", 10000);
//        System.out.println(person.getName());
//        System.out.println(person.getAge());
//        System.out.println(person.getGender());
//        System.out.println(person.getSalary());
//        System.out.println("---------------------");
//        Person person1 = new Person();
//        person1.setName("lisi");
//        person1.setAge(20);
//        person1.setGender("female");
//        person1.setSalary(20000);
//        System.out.println(person1.getName());
//        System.out.println(person1.getAge());
//        System.out.println(person1.getGender());
//        System.out.println(person1.getSalary());
//        person.print();
//        person1.print();
    }
}
